require "Dialogs"

Arena.Resize(130, 130)
Player.SetControlOverride(true)

state = 0
maxjump = 40
jump = 0
newpX = Player.absx
newpY = Player.absy
tableaux = 0
ForAchievement = Player.hp

timer = 0
tableaux = 0
Sans = {X = 490, Y = 261}
Paps = {X = 160, Y = 240}
Undyne = {X = 320, Y = 278}
AuxY = 90
phases = {0, 0}
if Encounter["StatusPhase3"][3] == "Challenge" then
	speed = 8
else
	speed = 6
end

Spears = {}
Bones1 = {}
Bones2 = {}
HuesosSuelo = {}
GB = {}
GB2 = {}
Sprites = {}

SetPPCollision(true)

function SummonWarning(num)
	Audio.PlaySound("encounter")
	Warning = {CreateSprite("Pixel", "BelowBullet"), CreateSprite("Pixel", "BelowBullet"), CreateSprite("Pixel", "BelowBullet")}
	Warning[1].color = {0.5, 0, 0}
	Warning[2].color = {0.5, 0, 0}
	Warning[3].color = {0.5, 0, 0}
	if num == 1 then
		Warning[1].Scale(2, 40)
		Warning[2].Scale(2, 40)
		Warning[3].Scale(Arena.width, 2)
		Warning[1].SetVar("Pos", {Arena.x + Arena.width/2 - 1, Arena.y + 25})
		Warning[2].SetVar("Pos", {Arena.x - Arena.width/2 + 1, Arena.y + 25})
		Warning[3].SetVar("Pos", {Arena.x, Arena.y + 44})
	elseif num == 2 then
		Warning[1].Scale(40, 2)
		Warning[2].Scale(40, 2)
		Warning[3].Scale(2, Arena.height)
		Warning[1].SetVar("Pos", {Arena.x + Arena.width/2 - 20, Arena.y + 4 + Arena.height})
		Warning[2].SetVar("Pos", {Arena.x + Arena.width/2 - 20, Arena.y + 6})
		Warning[3].SetVar("Pos", {Arena.x + Arena.width/2 - 39, Arena.y + 5 + Arena.height/2})
	elseif num == 3 then
		Warning[1].Scale(2, 40)
		Warning[2].Scale(2, 40)
		Warning[3].Scale(Arena.width, 2)
		Warning[1].SetVar("Pos", {Arena.x + Arena.width/2 - 1, Arena.y - 15 + Arena.height})
		Warning[2].SetVar("Pos", {Arena.x - Arena.width/2 + 1, Arena.y - 15 + Arena.height})
		Warning[3].SetVar("Pos", {Arena.x, Arena.y - 34 + Arena.height})
	else
		Warning[1].Scale(40, 2)
		Warning[2].Scale(40, 2)
		Warning[3].Scale(2, Arena.height)
		Warning[1].SetVar("Pos", {Arena.x - Arena.width/2 + 20, Arena.y + 4 + Arena.height})
		Warning[2].SetVar("Pos", {Arena.x - Arena.width/2 + 20, Arena.y + 6})
		Warning[3].SetVar("Pos", {Arena.x - Arena.width/2 + 39, Arena.y + 5 + Arena.height/2})
	end
	table.insert(Sprites, Warning[1])
	table.insert(Sprites, Warning[2])
	table.insert(Sprites, Warning[3])
end

function DestroyWarning()
	Audio.PlaySound("pierce")
	Warning[1].Remove()
	Warning[2].Remove()
	Warning[3].Remove()
	Warning = nil
end

function RecolorSoul()
	if state == 1 then
		Player.sprite.color = {0,60/255,1}
		Player.sprite.rotation = 0
	elseif state == 2 then
		Player.sprite.color = {0,60/255,1}
		Player.sprite.rotation = 270
	elseif state == 3 then
		Player.sprite.color = {0,60/255,1}
		Player.sprite.rotation = 180
	elseif state == 4 then
		Player.sprite.color = {0,60/255,1}
		Player.sprite.rotation = 90
	else
		Player.sprite.color = {1.0,0.0,0.0}
		Player.sprite.rotation = 0
	end
end

RecolorSoul()

function Update()
	DialogUpdate()
	SongTime = NewAudio.GetPlayTime("One")
	if timer == 0 then
		if Encounter["StatusPhase3"][3] == "Check Undyne" then
			Encounter.Call("SetHeadUndyne", "Hurt")
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][voice:undyne]Es en serio?![w:10]\nAsí es como vas a\ndesperdiciar tu\nturno?!", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][voice:undyne]Are you serious?![w:10]\nThat's how you are\ngoing to waste\nyour turn?!", "rightwide", 490.5, 395, 40, 90, 1)
			end
		elseif Encounter["StatusPhase3"][3] == "Plead" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][voice:undyne]Patético![w:10][func:SetHeadUndyne,Hurt]\nEres solo un cobarde.", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][voice:undyne]Pathetic![w:10][func:SetHeadUndyne,Hurt]\nYou're just a coward.", "rightwide", 490.5, 395, 40, 90, 1)
			end
		elseif Encounter["StatusPhase3"][3] == "Challenge" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][voice:undyne]Pequeño pedazo de\nbasura.", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][voice:undyne]You little piece of\ngarbage.", "rightwide", 490.5, 395, 40, 90, 1)
			end
		elseif Encounter["StatusPhase3"][3] == "Fake Attack" then
			Encounter.Call("SetHeadUndyne", "Hurt")
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][voice:undyne]Es en serio?![w:10]\nUn vegetal es incluso\nmás fuerte que tú!", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][voice:undyne]Are you serious?![w:10]\nA vegetable is even\nstronger than you!", "rightwide", 490.5, 395, 40, 90, 1)
			end
		elseif Encounter["StatusPhase3"][3] == "Fight Undyne" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][voice:undyne]Patético.", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][voice:undyne]Pathetic.", "rightwide", 490.5, 395, 40, 90, 1)
			end
		elseif Encounter["StatusPhase3"][3] == "Miss Undyne" then
			Encounter.Call("SetHeadUndyne", "Hurt")
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][voice:undyne]Es en serio?![w:10]\nNi siquiera me\npusiste un dedo\nencima.", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][voice:undyne]Are you serious?![w:10]\nYou didn't even put\na single finger on\nme.", "rightwide", 490.5, 395, 40, 90, 1)
			end
		elseif Encounter["StatusPhase3"][3] == "Item" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][voice:undyne]Patético.[w:10]\nQue desperdicio de\nturno.", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][voice:undyne]Pathetic.[w:10]\nWhat a waste of a\nturn.", "rightwide", 490.5, 395, 40, 90, 1)
			end
		elseif Encounter["StatusPhase3"][3] == "Spare" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][voice:undyne][color:f2c900]Perdonar[color:000000]?[w:10]\nHA![w:10] Patético.[w:10]\nEs demasiado tarde\npara eso.", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][voice:undyne][color:f2c900]Spare[color:000000]?[w:10]\nHA![w:10] Pathetic.[w:10]\nIt's too late for\nthat now.", "rightwide", 490.5, 395, 40, 90, 1)
			end
		elseif Encounter["StatusPhase3"][3] == "Flee" then
			Encounter.Call("SetHeadUndyne", "Mean Look")
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][voice:undyne]Eres solo un\ncobarde.", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][voice:undyne]You're just a\ncoward.", "rightwide", 490.5, 395, 40, 90, 1)
			end
		end
		Encounter.Call("ContinueMusic")
		timer = 1
	elseif timer == 1 and Bubbles[1] and not Bubbles[1].Activo then
		timer = 2
		if Encounter["StatusPhase3"][3] == "Check Undyne" then
			Encounter.Call("SetHeadUndyne", "Normal")
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][voice:undyne]Patético.[w:10]\nBueno[w:10], mi turno.[w:10000000000000] ", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][voice:undyne]Pathetic.[w:10]\nWell[w:10], my turn.[w:10000000000000] ", "rightwide", 490.5, 395, 40, 90, 1)
			end
		elseif Encounter["StatusPhase3"][3] == "Plead" or Encounter["StatusPhase3"][3] == "Fight Undyne" or Encounter["StatusPhase3"][3] == "Item" or Encounter["StatusPhase3"][3] == "Spare" or Encounter["StatusPhase3"][3] == "Flee" then
			Encounter.Call("SetHeadUndyne", "Normal")
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][voice:undyne]Bueno[w:10], mi turno.[w:10000000000000] ", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][voice:undyne]Well[w:10], my turn.[w:10000000000000] ", "rightwide", 490.5, 395, 40, 90, 1)
			end
			timer = 62
		elseif Encounter["StatusPhase3"][3] == "Challenge" then
			Encounter.Call("SetHeadUndyne", "Laugh 1")
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][voice:undyne]TE VOY A ENSEÑAR![w:10000000000000] ", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][voice:undyne]I WILL SHOW YOU![w:10000000000000] ", "rightwide", 490.5, 395, 40, 90, 1)
			end
			timer = 62
		elseif Encounter["StatusPhase3"][3] == "Fake Attack" then
			Encounter.Call("SetHeadUndyne", "Normal")
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][voice:undyne]Déjame mostrarte\ncómo se hace.[w:10000000000000] ", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][voice:undyne]Let me show you\nhow is it done.[w:10000000000000] ", "rightwide", 490.5, 395, 40, 90, 1)
			end
		elseif Encounter["StatusPhase3"][3] == "Miss Undyne" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][voice:undyne]Tienes miedo?[w:10]\nPATÉTICO![w:10][func:SetHeadUndyne,Normal]\nBueno[w:10], mi turno.[w:10000000000000] ", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][voice:undyne]Are you scared?[w:10]\nPATHETIC![w:10][func:SetHeadUndyne,Normal]\nWell[w:10], my turn.[w:10000000000000] ", "rightwide", 490.5, 395, 40, 90, 1)
			end
		end
	elseif timer >= 2 and timer < 180 then
		timer = timer + 1
	elseif timer >= 180 and phases[1] < 80 then
		if Encounter["GameMusic"] == "Wait 5" then
			Encounter.Call("ContinueMusic")
			Encounter.Call("SwingUndyne")
		else
			if phases[1] == 0 then
				if Encounter["StatusPhase3"][3] == "Challenge" then
					Encounter.Call("SetHeadUndyne", "Hurt")
				end
				Bubble("", "", 0, 0, 0, 0, 1)
				phases[1] = 1
			elseif phases[1] == 1 then
				if SongTime > 0.7 then
					if not Green then
						Green = CreateSprite("Specials/Green Mode", "BelowPlayer")
						Shield = CreateSprite("Specials/Shield 1", "BelowPlayer")
						Shield.SetVar("Look", "Up")
						Encounter["Dont"] = true
						Black = CreateSprite("Pixel", "BelowArena")
						Black.color = {0,0,0}
						Black.Scale(640, 480)
						Black.MoveTo(320, 240)
					end
					if SongTime <= 0.9 then
						Arena.Resize(130 - 55/0.2*(SongTime - 0.7), 130 - 55/0.2*(SongTime - 0.7))
						AuxY = 90 + 107.5/0.2*(SongTime - 0.7)
						newpY = 160 + 80/0.2*(SongTime - 0.7)
						Green.alpha = 1/0.2*(SongTime - 0.7)
						Shield.alpha = 1/0.2*(SongTime - 0.7)
						Black.alpha = 0.5/0.2*(SongTime - 0.7)
					else
						Arena.Resize(75, 75)
						AuxY = 197.5
						newpY = 240
						Green.alpha = 1
						Shield.alpha = 1
						Black.alpha = 0.5
						phases[1] = 2
					end
				end
			elseif phases[1] >= 2 and phases[1] <= 8 then
				if SongTime > 1 + 0.2*(phases[1] - 2) then
					local rot = -90 + 90*math.random(4)
					if phases[1] == 2 then
						rot = 0
					elseif (phases[1] == 4 and speed == 6) or (phases[1] == 6 and speed == 8) then
						local rot1 = -90 + 90*math.random(4)
						local rot2 = 0
						repeat
							rot2 = -90 + 90*math.random(4)
						until rot1 ~= rot2
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0, "BelowBullet"), Distance = 340, Direction = rot1, Speed = speed/3, Turn = 9})
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0, "BelowBullet"), Distance = 365, Direction = rot1, Speed = speed/3, Turn = 10})
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0, "BelowBullet"), Distance = 390, Direction = rot1, Speed = speed/3, Turn = 11})
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0, "BelowBullet"), Distance = 415, Direction = rot1, Speed = speed/3, Turn = 12})
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0, "BelowBullet"), Distance = 440, Direction = rot1, Speed = speed/3, Turn = 13})
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0, "BelowBullet"), Distance = 465, Direction = rot1, Speed = speed/3, Turn = 14})
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0, "BelowBullet"), Distance = 415, Direction = rot2, Speed = speed/3, Turn = 12})
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0, "BelowBullet"), Distance = 440, Direction = rot2, Speed = speed/3, Turn = 13})
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0, "BelowBullet"), Distance = 465, Direction = rot2, Speed = speed/3, Turn = 14})
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0, "BelowBullet"), Distance = 490, Direction = rot2, Speed = speed/3, Turn = 15})
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0, "BelowBullet"), Distance = 515, Direction = rot2, Speed = speed/3, Turn = 16})
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0, "BelowBullet"), Distance = 540, Direction = rot2, Speed = speed/3, Turn = 17})
					end
					table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0), Distance = 360, Direction = rot, Speed = speed, Turn = phases[1] - 1})
					phases[1] = phases[1] + 1
				end
			elseif phases[1] >= 9 and phases[1] <= 13 then
				if SongTime > 5.4 + 0.2*(phases[1] - 9) then
					local rot = -90 + 90*math.random(4)
					table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0), Distance = 360, Direction = rot, Speed = speed, Turn = phases[1] + 9})
					phases[1] = phases[1] + 1
				end
			elseif phases[1] >= 13 and phases[1] <= 17 then
				if SongTime > 6.2 + 0.3*(phases[1] - 13) then
					local rot = -90 + 90*math.random(4)
					if phases[1] == 17 then
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0), Distance = 360 + speed*18, Direction = rot, Speed = speed, Turn = phases[1] + 9})
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Yellow", 0, 0), Distance = 360, Direction = rot, Speed = speed, Backwards = true})
						local rot1 = -90 + 90*math.random(4)
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0), Distance = 360 + speed*30, Direction = rot1, Speed = speed, Turn = phases[1] + 10})
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0), Distance = 360 + speed*54, Direction = (rot1 + 180)%360, Speed = speed, Turn = phases[1] + 12})
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0), Distance = 360 + speed*42, Direction = (rot1 + 90)%360, Speed = speed, Turn = phases[1] + 11})
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0), Distance = 360 + speed*66, Direction = (rot1 + 270)%360, Speed = speed, Turn = phases[1] + 13})
					else
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Yellow", 0, 0), Distance = 360, Direction = rot, Speed = speed, Backwards = true})
					end
					phases[1] = phases[1] + 1
				end
			elseif phases[1] >= 18 and phases[1] <= 20 then
				if SongTime > 10.3 + (phases[1] - 18) then
					local rot = -90 + 90*math.random(4)
					if phases[1] == 20 then
						table.insert(Bones1, {Bullet = CreateProjectileAbs("Bullets/Bones/BoneP", 0, 0), Distance = 360, Direction = rot, Speed = speed, Blue = true})
					else
						table.insert(Bones1, {Bullet = CreateProjectileAbs("Bullets/Bones/BoneP", 0, 0), Distance = 360, Direction = rot, Speed = speed})
					end
					phases[1] = phases[1] + 1
				end
			elseif phases[1] >= 21 and phases[1] <= 23 then
				if SongTime > 13 + 0.3*(phases[1] - 21) then
					local rot = -90 + 90*math.random(4)
					if phases[1] == 23 then
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Yellow", 0, 0), Distance = 360, Direction = rot, Speed = speed, Backwards = true})
					else
						table.insert(Bones1, {Bullet = CreateProjectileAbs("Bullets/Bones/BoneP", 0, 0), Distance = 360, Direction = rot, Speed = speed})
					end
					phases[1] = phases[1] + 1
				end
			elseif phases[1] >= 24 and phases[1] <= 27 then
				if SongTime > 14 + 0.3*(phases[1] - 24) then
					local rot = -90 + 90*math.random(4)
					if phases[1] == 24 then
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0), Distance = 360 + speed*12, Direction = rot, Speed = speed, Turn = phases[1]})
					elseif phases[1] == 25 then
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Yellow", 0, 0), Distance = 360, Direction = rot, Speed = speed, Backwards = true})
					elseif phases[1] == 26 then
						table.insert(Bones1, {Bullet = CreateProjectileAbs("Bullets/Bones/BoneP", 0, 0), Distance = 360 + speed*12, Direction = rot, Speed = speed})
					else
						table.insert(Bones1, {Bullet = CreateProjectileAbs("Bullets/Bones/BoneP", 0, 0), Distance = 360 + speed*12, Direction = rot, Speed = speed, Blue = true})
					end
					if phases[1] == 27 then
						Audio.PlaySound("gasterintro2")
						if math.random(2) == 1 then
							table.insert(GB, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Type = "Papyrus", Animacion = {DatosIniciales = {X = 690, Y = 240, rotation = 90}, DatosFinales = {X = 540, Y = 240, rotation = -90}}, Delay = 80, Duration = 40})
						else
							table.insert(GB, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Type = "Papyrus", Animacion = {DatosIniciales = {X = -50, Y = 240, rotation = -90}, DatosFinales = {X = 100, Y = 240, rotation = 90}}, Delay = 80, Duration = 40})
						end
					end
					phases[1] = phases[1] + 1
				end
			elseif phases[1] >= 28 and phases[1] <= 32 then
				if SongTime > 17.3 + 0.3*(phases[1] - 28) then
					local rot = -90 + 90*math.random(4)
					if phases[1] >= 31 then
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Yellow", 0, 0), Distance = 360, Direction = rot, Speed = speed, Backwards = true})
					else
						table.insert(Spears, {Bullet = CreateProjectileAbs("Bullets/Arrow Blue", 0, 0), Distance = 360, Direction = rot, Speed = speed, Turn = phases[1]})
					end
					phases[1] = phases[1] + 1
				end
			elseif phases[1] == 33 then
				if SongTime > 20.1 then
					Black2 = CreateSprite("Pixel","Top")
					Black2.MoveTo(320, 240)
					Black2.Scale(640, 480)
					Black2.color = {0,0,0}
					if ForAchievement == Player.hp and speed == 8 and string.sub(GetAlMightyGlobal("Archivimentazo"), 15, 15) == "0" then
						SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 14).."1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 16))
						Encounter["LogroDesbloqueado"] = {Timer = 0, Icon = 15}
					end
					Green.Remove()
					Green = nil
					Shield.Remove()
					Shield = nil
					Black.Remove()
					Black = nil
					for i=1,#Spears do
						Spears[i - tableaux].Bullet.Remove()
						table.remove(Spears, i - tableaux)
						tableaux = tableaux + 1
					end
					tableaux = 0
					for i=1,#Bones1 do
						Bones1[i - tableaux].Bullet.Remove()
						table.remove(Bones1, i - tableaux)
						tableaux = tableaux + 1
					end
					tableaux = 0
					for i=1,#GB do
						GB[i - tableaux].Sprite.Remove()
						if GB[i - tableaux].Laser then
							GB[i - tableaux].Laser.Misil.Remove()
							GB[i - tableaux].Laser.Cuerpo.Remove()
							GB[i - tableaux].Laser.Rafaga.Remove()
						end
						table.remove(GB, i - tableaux)
						tableaux = tableaux + 1
					end
					tableaux = 0
					Arena.Resize(360, 130)
					AuxY = 90
					newpY = 103
					Paps.X = 800
					Undyne.X = 800
					Encounter.Call("PapyrusAlpha", 0)
					Encounter.Call("UndyneAlpha", 0)
					Sans.X = 320
					Encounter.Call("SetSansHead", "Angry")
					Encounter.Call("SetHeadUndyne", "Normal")
					Encounter["Dont"] = nil
					phases[1] = 34
				end
			elseif phases[1] == 34 then
				if SongTime > 21.3 then
					Black2.Remove()
					Black2 = nil
					state = 1
					RecolorSoul()
					phases[1] = 35
				end
			elseif phases[1] >= 35 and phases[1] <= 41 then
				if SongTime > 21.3 + 1.2*(phases[1] - 35) then
					local randomizador = math.random(4)
					table.insert(Bones2, {Body = CreateProjectileAbs("Bullets/Bones/BodyS", 500, 96 + 8*randomizador), Head = CreateProjectileAbs("Bullets/Bones/HeadS", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/HeadS", 0, 0), Scale = -10 + 16*randomizador, Vel = -3})
					table.insert(Bones2, {Body = CreateProjectileAbs("Bullets/Bones/BodyS", 500, 171 + 8*randomizador), Head = CreateProjectileAbs("Bullets/Bones/HeadS", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/HeadS", 0, 0), Scale = 94 - 16*randomizador, Vel = -3})
					table.insert(Bones2, {Body = CreateProjectileAbs("Bullets/Bones/BodyS", 140, 96 + 8*randomizador), Head = CreateProjectileAbs("Bullets/Bones/HeadS", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/HeadS", 0, 0), Scale = -10 + 16*randomizador, Vel = 3})
					table.insert(Bones2, {Body = CreateProjectileAbs("Bullets/Bones/BodyS", 140, 171 + 8*randomizador), Head = CreateProjectileAbs("Bullets/Bones/HeadS", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/HeadS", 0, 0), Scale = 94 - 16*randomizador, Vel = 3})
					phases[1] = phases[1] + 1
				end
			elseif phases[1] == 42 then
				if SongTime > 30.9 then
					Arena.Resize(130, 130)
					phases[1] = 43
				end
			elseif phases[1] == 43 or phases[1] == 45 then
				if SongTime > 31.2 + 0.82*(phases[1] - 43) then
					local oldstate = state
					repeat
						state = math.random(4)
					until state ~= oldstate and state ~= 1
					jump = -100
					if state == 2 then
						Encounter["Sans"]["Animation"] = "Left"
						SummonWarning(4)
					elseif state == 3 then
						Encounter["Sans"]["Animation"] = "Up"
						SummonWarning(3)
					else
						Encounter["Sans"]["Animation"] = "Right"
						SummonWarning(2)
					end
					Encounter["Sans"]["Timer2"] = 0
					RecolorSoul()
					phases[1] = phases[1] + 1
				end
			elseif phases[1] == 44 or phases[1] == 46 then
				if SongTime > 31.94 + 0.82*(phases[1] - 44) then
					DestroyWarning()
					if state == 3 then
						for i=Arena.x - Arena.width/2 + 5,Arena.x + Arena.width/2 - 5,12 do
							table.insert(HuesosSuelo, {Misil = CreateProjectileAbs("Bullets/Bones/BodyS", i, Arena.y + 5 + Arena.height), Head = CreateProjectileAbs("Bullets/Bones/HeadS", 0, 0), Scale = {MaxHeight = 34, Vel = 4}, Rotacion = 180, Duration = 20})
						end
					elseif state == 4 then
						for i=Arena.y + 10,Arena.y + Arena.height,12 do
							table.insert(HuesosSuelo, {Misil = CreateProjectileAbs("Bullets/Bones/BodyS", Arena.x + Arena.width/2, i), Head = CreateProjectileAbs("Bullets/Bones/HeadS", 0, 0), Scale = {MaxHeight = 34, Vel = 4}, Rotacion = 90, Duration = 20})
						end
					else
						for i=Arena.y + 10,Arena.y + Arena.height,12 do
							table.insert(HuesosSuelo, {Misil = CreateProjectileAbs("Bullets/Bones/BodyS", Arena.x - Arena.width/2, i), Head = CreateProjectileAbs("Bullets/Bones/HeadS", 0, 0), Scale = {MaxHeight = 34, Vel = 4}, Rotacion = 270, Duration = 20})
						end
					end
					phases[1] = phases[1] + 1
				end
			elseif phases[1] == 47 then
				if SongTime > 34.5 then
					state = 1
					Encounter["PHP"] = true
					maxjump = 12
					jump = -100
					Encounter["Sans"]["Animation"] = "Down"
					Encounter["Sans"]["Timer2"] = 0
					RecolorSoul()
					table.insert(GB2, {Sprite = CreateSprite("Bullets/GB Sans/0","BelowBullet"), Type = "Sans", Animacion = {DatosIniciales = {X = 690, Y = 530, rotation = 0}, DatosFinales = {X = 160, Y = 100, rotation = 90}}, Delay = 30, Duration = 30})
					Audio.PlaySound("gasterintro")
					phases[1] = 48
				end
			elseif phases[1] == 48 then
				if SongTime > 35 then
					Encounter.Call("SetSansHead", "Presure")
					phases[1] = 49
				end
			elseif phases[1] == 49 then
				if SongTime > 36.5 then
					Encounter["Sans"]["Animation"] = "Normal"
					Encounter.Call("SetSansHead", "Angry")
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:sans][novoice][waittall:3]es esto lo que\nquieres?[w:10000000] ", "rightwide", 490.5, 315, 40, 90, 1)
					else
						Bubble("[noskip][font:sans][novoice][waittall:3]is this what you want?[w:10000000] ", "rightwide", 490.5, 315, 40, 90, 1)
					end
					maxjump = 40
					phases[1] = 50
				end
			elseif phases[1] == 50 then
				if SongTime > 40.5 then
					Encounter.Call("SetSansHead", "Normal")
					if GetAlMightyGlobal("SkipMonologuePhase3") then
						allowskip = true
					end
					Encounter["BackgroundAnimation"] = "Increase"
					Bubble("", "", 0, 0, 0, 0, 1)
					phases[1] = 51
				end
			elseif phases[1] == 51 then
				if SongTime > 41.7 then
					Encounter["Sans"]["Animation"] = "Stop"
					Encounter["Sans"]["Timer"] = 0
					Encounter.Call("SetSansHead", "mmm...")
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:sans][voice:sans][waittall:0.5]chico[w:2], tengo la\nsensación de que no\nestás planeando en\nrendirte.[w:10000000] ", "rightwide", 490.5, 315, 40, 90, 1)
					else
						Bubble("[noskip][font:sans][voice:sans][waittall:0.5]kid[w:2], i get the feeling\nyou aren't planning on\ngiving up.[w:10000000] ", "rightwide", 490.5, 315, 40, 90, 1)
					end
					phases[1] = 52
				end
			elseif phases[1] == 52 then
				if SongTime > 44.7 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:sans][voice:sans][waittall:0.5]es una pena[w:5], en serio.[w:5]\nA sans le hubiera\nencantado ver un buen\nfinal.[w:10000000] ", "rightwide", 490.5, 315, 40, 90, 1)
					else
						Bubble("[noskip][font:sans][voice:sans][waittall:0.5]it's a shame[w:5], really.[w:5]\nsans would have loved\nto see a good ending.[w:10000000] ", "rightwide", 490.5, 315, 40, 90, 1)
					end
					phases[1] = 53
				end
			elseif phases[1] == 53 then
				if SongTime > 50.1 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:sans][voice:sans][waittall:0.5]qué?[w:5]\nlos dos sabemos que\nno estoy tan vivo\ncomo lo he estado.[w:10000000] ", "rightwide", 490.5, 315, 40, 90, 1)
					else
						Bubble("[noskip][font:sans][voice:sans][waittall:0.5]what?[w:5]\nwe both know i'm not\nas alive as i have been.[w:10000000] ", "rightwide", 490.5, 315, 40, 90, 1)
					end
					phases[1] = 54
				end
			elseif phases[1] == 54 then
				if SongTime > 54.3 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:sans][voice:sans][waittall:0.5]quién sabe lo que\nestaría haciendo si\nestuviera aquí de\nverdad.[w:10000000] ", "rightwide", 490.5, 315, 40, 90, 1)
					else
						Bubble("[noskip][font:sans][voice:sans][waittall:0.5]who knows what i'd be\ndoing if i was here\nfor real.[w:10000000] ", "rightwide", 490.5, 315, 40, 90, 1)
					end
					phases[1] = 55
				end
			elseif phases[1] == 55 then
				if SongTime > 57.3 then
					Encounter.Call("SetSansHead", "Worried")
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:sans][voice:sans][waittall:0.5]lo siento[w:5], chico.[w:10000000] ", "rightwide", 490.5, 315, 40, 90, 1)
					else
						Bubble("[noskip][font:sans][voice:sans][waittall:0.5]i'm sorry[w:5], kid.[w:10000000] ", "rightwide", 490.5, 315, 40, 90, 1)
					end
					phases[1] = 56
				end
			elseif phases[1] == 56 then
				if SongTime > 59.7 then
					phases[2] = 1
					Encounter.Call("SetSansHead", "Normal")
					Encounter["Sans"]["Animation"] = "Normal"
					Encounter["Legs"].SendToTop()
					Encounter["HandL"].SendToTop()
					Encounter["HandR"].SendToTop()
					for i=1,#Encounter["LegsParts"] do
						Encounter["LegsParts"][i].SendToTop()
					end
					Bubble("", "", 0, 0, 0, 0, 1)
					if SongTime <= 60.9 then
						Paps.X = 450 - 120/1.2*(SongTime - 59.7)
						Sans.X = 320 + 170/1.2*(SongTime - 59.7)
						Undyne.X = 190 - 40/1.2*(SongTime - 59.7)
					else
						Paps.X = 330
						Sans.X = 490
						Undyne.X = 150
						Encounter.Call("SetHead", "Thinking")
						if GetAlMightyGlobal("Idioma") == "Spanish" then
							Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]Ellos no son\nreales.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
						else
							Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]They aren't real.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
						end
						Encounter.Call("AttackAnim", 1)
						phases[1] = 57
					end
					Encounter.Call("PapyrusAlpha", 1)
					Encounter.Call("UndyneAlpha", 1)
				end
			elseif phases[1] == 57 then
				if SongTime > 63.9 then
					Encounter.Call("SetHead", "Disgust")
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]No podía\nsoportar la idea\nde matarte.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					else
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]I couldn't stand\nthe thought of\nkilling you.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					end
					phases[1] = 58
				end
			elseif phases[1] == 58 then
				if SongTime > 66.6 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]He estado\nhaciendo esto\npor su bien.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					else
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]I've been doing\nthis for their\nsake.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					end
					phases[1] = 59
				end
			elseif phases[1] == 59 then
				if SongTime > 69.9 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]Pero[w:5], es esto lo\nque hubieran\nquerido?[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					else
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]But[w:5], is this even\nwhat they would\nhave wanted?[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					end
					phases[1] = 60
				end
			elseif phases[1] == 60 then
				if SongTime > 76.5 then
					Encounter.Call("SetHead", "Thinking")
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]Estoy teniendo\ndudas.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					else
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]I'm having second\nthoughts.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					end
					phases[1] = 61
				end
			elseif phases[1] == 61 then
				if SongTime > 78.9 then
					Encounter.Call("SetHead", "Sad")
					Encounter["BackgroundAnimation"] = "Fall"
					Bubble("", "", 0, 0, 0, 0, 1)
					phases[1] = 62
				end
			elseif phases[1] == 62 then
				if SongTime > 81 then
					if SongTime <= 81.9 then
						Undyne.X = -250 + 400*math.cos(math.rad(90/0.9*(SongTime - 81)))
					else
						Undyne.X = -250
						Encounter["Undyne"]["DontShow"] = true
						phases[1] = 63
					end
				end
			elseif phases[1] == 63 then
				if SongTime > 83.4 then
					if SongTime <= 84.5 then
						Sans.X = 890 - 400*math.cos(math.rad(90/0.9*(SongTime - 83.4)))
					else
						Sans.X = 890
						phases[1] = 64
					end
				end
			elseif phases[1] == 64 then
				if SongTime > 84.9 then
					Encounter.Call("SetHead", "err...")
					phases[1] = 65
				end
			elseif phases[1] == 65 then
				if SongTime > 86.1 then
					Encounter.Call("SetHead", "umm...")
					phases[1] = 66
				end
			elseif phases[1] == 66 then
				if SongTime > 87.3 then
					Encounter.Call("SetHead", "err...")
					phases[1] = 67
				end
			elseif phases[1] == 67 then
				if SongTime > 88.5 then
					Encounter.Call("SetHead", "Regreat")
					phases[1] = 68
				end
			elseif phases[1] == 68 then
				if SongTime > 89.7 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:4]Yo . . .[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					else
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:4]I . . .[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					end
					phases[1] = 69
				end
			elseif phases[1] == 69 then
				if SongTime > 93.3 then
					Bubble("", "", 0, 0, 0, 0, 1)
					phases[1] = 70
				end
			elseif phases[1] == 70 then
				if SongTime > 98.4 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]Gran parte de mí\nes muy estúpida\ncomo para seguir\ncreyendo.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					else
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]A big part of me\nis stupid enough\nto still believe.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					end
					phases[1] = 71
				end
			elseif phases[1] == 71 then
				if SongTime > 103.5 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]Este es el\nmomento en el\nque Sans te\nhubiera matado.[w:10000000] ", "rightwide", 490.5, 395, 34, 90, 1)
					else
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]This is the moment\nsans would have\nkilled you.[w:10000000] ", "rightwide", 490.5, 395, 34, 90, 1)
					end
					phases[1] = 72
				end
			elseif phases[1] == 72 then
				if SongTime > 108 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]Pero no creo que\nél quiera que\nsea como él...[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					else
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]But I don't think\nhe wants me to\nbe like him...[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					end
					phases[1] = 73
				end
			elseif phases[1] == 73 then
				if SongTime > 113.26 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]Porque la verdad\nes que[w:10], no lo\nsoy.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					else
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]Because the\ntruth is[w:10], I'm not.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					end
					phases[1] = 74
				end
			elseif phases[1] == 74 then
				if SongTime > 117.6 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]Incluso después\nde lo que hiciste[w:3],\ntodavía no puedo\nmatarte.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					else
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]Even after all\nyou did[w:3], I still\ncan't kill you.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					end
					phases[1] = 75
				end
			elseif phases[1] == 75 then
				if SongTime > 122.7 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]Nadie merece\nmorir así.[w:10]\nNi siquiera tú.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					else
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]No one deserves\nto die like this.[w:10]\nNot even you.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					end
					phases[1] = 76
				end
			elseif phases[1] == 76 then
				if SongTime > 127.2 then
					Encounter.Call("SetHead", "err...")
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:papyrus][voice:papyrus]Por favor\nperdóname.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					else
						Bubble("[noskip][font:papyrus][voice:papyrus]Please forgive\nme.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					end
					phases[1] = 77
				end
			elseif phases[1] == 77 then
				if SongTime > 131.1 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]Pero no puedo\nmirar más allá\nde nuestra\namistad perdida.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					else
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]But I can't look\npast our lost\nfriendship.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					end
					phases[1] = 78
				end
			elseif phases[1] == 78 then
				if SongTime > 134.1 then
					Encounter.Call("SetHead", "Regreat")
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]Mi incredulidad\nfue fingida.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					else
						Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]My disbelief was\nfaked.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
					end
					phases[1] = 79
				end
			elseif phases[1] == 79 then
				if SongTime > 135.9 then
					Bubble("", "", 0, 0, 0, 0, 1)
					phases[1] = 80
					timer = 180
				end
			end
			if phases[2] == 0 then
				if SongTime > 40.5 then
					if SongTime <= 44.5 then
						Paps.X = 550 - 100/4*(SongTime - 40.5)
						Undyne.X = 90 + 100/4*(SongTime - 40.5)
						Encounter.Call("PapyrusAlpha", 1/4*(SongTime - 40.5))
						Encounter.Call("UndyneAlpha", 1/4*(SongTime - 40.5))
					else
						Paps.X = 450
						Undyne.X = 190
						Encounter.Call("PapyrusAlpha", 1)
						Encounter.Call("UndyneAlpha", 1)
						phases[2] = 1
					end
				end
			end
			if NewAudio.isStopped("One") and Encounter["GameMusic"] == "End" then
				Paps.X = 330
				Sans.X = 900
				Undyne.X = -250
				Encounter["Undyne"]["DontShow"] = true
				Encounter.Call("AttackAnim", 1)
				Encounter["BackgroundAnimation"] = "Fall"
				Bubble("", "", 0, 0, 0, 0, 1)
				phases[1] = 180
				timer = 180
			end
		end
	elseif timer == 180 and phases[1] == 80 then
		Encounter.Call("SetHead", "nyeh...")
		timer = 181
	elseif timer >= 181 and timer < 210 then
		timer = timer + 1
	elseif timer == 210 then
		Encounter.Call("AttackAnim", 4)
		timer = 211
	elseif timer >= 211 and timer < 330 then
		timer = timer + 1
	elseif timer == 330 and not skiped then
		if not Black2 then
			Black2 = CreateSprite("Pixel", "Top")
			Black2.MoveTo(320, 240)
			Black2.Scale(640, 480)
			Black2.color = {0,0,0}
			Black2.alpha = 0
		else
			Black2.alpha = Black2.alpha + 0.02
			if Black2.alpha >= 1 then
				Black2.Remove()
				if Skip then
					Skip.Remove()
				end
				allowskip = nil
				if Black then
					Black.Remove()
				end
				SetAlMightyGlobal("SkipMonologuePhase3", true)
				Encounter.Call("InitiatePhase4", 1)
				Encounter["nextwaves"] = {"Final Attack"}
				State("DEFENDING")
			end
		end
	end
	if allowskip then
		if not Skip then
			Skip = CreateSprite("Specials/Skip")
			Skip.MoveTo(528, 466)
			Skip.alpha = 0
		end
		if Skip.alpha < 1 then
			Skip.alpha = Skip.alpha + 0.02
		end
		if Input.GetKey("N") > 0 and not skiped then
			skiped = true
			Black2 = CreateSprite("Pixel", "Top")
			Black2.MoveTo(320, 240)
			Black2.Scale(640, 480)
			Black2.color = {0,0,0}
			phases[1] = 80
			timer = 330
			Bubble("", "", 0, 0, 0, 0, 1)
			Encounter["GameMusic"] = "Fade"
			Encounter["Volumen"] = 1
			Encounter["Animation"] = "None"
			Encounter.Call("AttackAnim", 4)
			Encounter.Call("PapyrusAlpha", 1)
		end
	end
	if skiped and Encounter["GameMusic"] == "End" then
		allowskip = nil
		skiped = nil
	end
	if Shield then
		if Input.Down == 1 and Input.Up <= 0 and Input.Left <= 0 and Input.Right <= 0 and Shield.GetVar("Look") ~= "Down" then
			Shield.SetVar("Speed", math.min(math.abs(Shield.rotation - 180), math.abs(Shield.rotation + 180))/3)
			Shield.SetVar("Look", "Down")
			Shield.SetVar("Timer", 0)
		elseif Input.Up == 1 and Input.Down <= 0 and Input.Left <= 0 and Input.Right <= 0 and Shield.GetVar("Look") ~= "Up" then
			Shield.SetVar("Speed", math.min(math.abs(Shield.rotation - 360), math.abs(Shield.rotation))/3)
			Shield.SetVar("Look", "Up")
			Shield.SetVar("Timer", 0)
		elseif Input.Left == 1 and Input.Down <= 0 and Input.Up <= 0 and Input.Right <= 0 and Shield.GetVar("Look") ~= "Left" then
			Shield.SetVar("Speed", math.min(math.abs(Shield.rotation - 90), math.abs(Shield.rotation + 270))/3)
			Shield.SetVar("Look", "Left")
			Shield.SetVar("Timer", 0)
		elseif Input.Right == 1 and Input.Down <= 0 and Input.Left <= 0 and Input.Up <= 0 and Shield.GetVar("Look") ~= "Right" then
			Shield.SetVar("Speed", math.min(math.abs(Shield.rotation - 270), math.abs(Shield.rotation + 90))/3)
			Shield.SetVar("Look", "Right")
			Shield.SetVar("Timer", 0)
		end
		if Shield.GetVar("Timer") then
			Shield.SetVar("Timer", Shield.GetVar("Timer") + 1)
			if Shield.GetVar("Timer") <= 2 then
				if Shield.GetVar("Look") == "Down" then
					if Shield.rotation > 0 and Shield.rotation < 180 then
						Shield.rotation = Shield.rotation + Shield.GetVar("Speed")
					elseif Shield.rotation > 180 or Shield.rotation == 0 then
						Shield.rotation = Shield.rotation - Shield.GetVar("Speed")
					end
				elseif Shield.GetVar("Look") == "Up" then
					if Shield.rotation > 180 then
						Shield.rotation = Shield.rotation + Shield.GetVar("Speed")
					elseif Shield.rotation > 0 and Shield.rotation <= 180 then
						Shield.rotation = Shield.rotation - Shield.GetVar("Speed")
					end
				elseif Shield.GetVar("Look") == "Right" then
					if Shield.rotation > 90 and Shield.rotation < 270 then
						Shield.rotation = Shield.rotation + Shield.GetVar("Speed")
					elseif Shield.rotation <= 90 or Shield.rotation > 270 then
						Shield.rotation = Shield.rotation - Shield.GetVar("Speed")
					end
				elseif Shield.GetVar("Look") == "Left" then
					if Shield.rotation < 90 or Shield.rotation > 270 then
						Shield.rotation = Shield.rotation + Shield.GetVar("Speed")
					elseif Shield.rotation > 90 and Shield.rotation <= 270 then
						Shield.rotation = Shield.rotation - Shield.GetVar("Speed")
					end
				end
			else
				if Shield.GetVar("Look") == "Down" then
					Shield.rotation = 180
				elseif Shield.GetVar("Look") == "Up" then
					Shield.rotation = 0
				elseif Shield.GetVar("Look") == "Right" then
					Shield.rotation = 270
				elseif Shield.GetVar("Look") == "Left" then
					Shield.rotation = 90
				end
			end
		end
	end
	shake = {}
	for i=1,#GB do
		local gb = GB[i - tableaux]
		if not gb.X then
			gb.X = gb.Sprite.x
		end
		if not gb.Y then
			gb.Y = gb.Sprite.y
		end
		if gb.Type == "Papyrus" then
			gb.distance = 26
		elseif gb.Type == "Sans" then
			gb.distance = 38
		end
		gb.Sprite.xscale = (gb.Scale or 1)
		if gb.Animacion then
			if not gb.Animacion.timer then
				gb.Animacion.timer = 0
			end
			gb.Animacion.timer = gb.Animacion.timer + 1
			gb.X = gb.Animacion.DatosIniciales.X + (gb.Animacion.DatosFinales.X - gb.Animacion.DatosIniciales.X)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30))))
			gb.Y = gb.Animacion.DatosIniciales.Y + (gb.Animacion.DatosFinales.Y - gb.Animacion.DatosIniciales.Y)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30))))
			gb.Sprite.MoveTo(gb.X, gb.Y)
			while gb.Animacion.DatosIniciales.rotation >= 360 or gb.Animacion.DatosIniciales.rotation < 0 do
				if gb.Animacion.DatosIniciales.rotation < 0 then
					gb.Animacion.DatosIniciales.rotation = gb.Animacion.DatosIniciales.rotation + 360
				else
					gb.Animacion.DatosIniciales.rotation = gb.Animacion.DatosIniciales.rotation - 360
				end
			end
			while gb.Animacion.DatosFinales.rotation >= 360 or gb.Animacion.DatosFinales.rotation < 0 do
				if gb.Animacion.DatosFinales.rotation < 0 then
					gb.Animacion.DatosFinales.rotation = gb.Animacion.DatosFinales.rotation + 360
				else
					gb.Animacion.DatosFinales.rotation = gb.Animacion.DatosFinales.rotation - 360
				end
			end
			if gb.Animacion.DatosFinales.rotation - gb.Animacion.DatosIniciales.rotation <= 180 and gb.Animacion.DatosFinales.rotation - gb.Animacion.DatosIniciales.rotation >= -180 then
				gb.Sprite.rotation = gb.Animacion.DatosIniciales.rotation - (gb.Animacion.DatosIniciales.rotation - gb.Animacion.DatosFinales.rotation)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30))))
			else
				gb.Sprite.rotation = gb.Animacion.DatosIniciales.rotation - (360 - (gb.Animacion.DatosFinales.rotation - 180 + gb.Animacion.DatosIniciales.rotation - 180)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30)))))
			end
			if gb.Animacion.timer >= (gb.Animacion.VelAppearing or 30) then
				gb.Animacion = nil
				gb.Done = true
			end
		else
			if gb.Rotation and not gb.Done then
				gb.Sprite.rotation = gb.Rotation
			end
			gb.Delay = gb.Delay - 1
		end
		if gb.Vel then
			gb.X = gb.X - gb.Vel*math.sin(math.rad(gb.Sprite.rotation))
			gb.Y = gb.Y + gb.Vel*math.cos(math.rad(gb.Sprite.rotation))
			gb.Vel = gb.Vel*1.1
			if gb.X < -100 or gb.X > 740 or gb.Y < -100 or gb.Y > 580 then
				gb.Vel = 0
			end
		end
		gb.Sprite.MoveTo(gb.X, gb.Y)
		if (gb.Delay < 0 and gb.Type == "Papyrus") or (gb.Delay < 6 and gb.Type == "Sans") then
			if gb.Delay == 5 then
				gb.Sprite.Set("Bullets/GB Sans/1")
			elseif gb.Delay == 3 then
				gb.Sprite.Set("Bullets/GB Sans/2")
			elseif gb.Delay == 1 then
				gb.Sprite.Set("Bullets/GB Sans/3")
			elseif gb.Delay == -1 then
				if gb.Type == "Papyrus" then
					gb.Sprite.Set("Bullets/GB Papyrus/1")
				else
					gb.Sprite.SetAnimation({"Bullets/GB Sans/4","Bullets/GB Sans/5"}, 0.04)
				end
				gb.Vel = 2
				Audio.PlaySound("gasterfire")
			elseif gb.Delay <= -2 then
				if gb.Duration > 0 then
					gb.Duration = gb.Duration - 1
					if not gb.Laser then
						gb.Laser = {Misil = CreateProjectileAbs("Bullets/GB Laser 2", gb.X + (11 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (11 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation))), Cuerpo = CreateProjectileAbs("Pixel", gb.X + (22 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (22 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation))), Rafaga = CreateProjectileAbs("Bullets/GB Rafaga 1", gb.X + (-1 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (-1 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))}
						gb.Laser.Misil.sprite.xscale = 0
						gb.Laser.Misil.sprite.rotation = gb.Sprite.rotation
						gb.Laser.Cuerpo.sprite.Scale(0, 0)
						gb.Laser.Cuerpo.sprite.rotation = gb.Sprite.rotation
						gb.Laser.Rafaga.sprite.Scale(0, 0)
						gb.Laser.Rafaga.sprite.rotation = gb.Sprite.rotation
						gb.Laser.Rafaga.sprite.SetAnimation({"Bullets/GB Rafaga 1", "Bullets/GB Rafaga 2"}, 0.08)
						gb.Laser.Scale = 0
					else
						gb.Laser.Misil.MoveToAbs(gb.X + (11 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (11 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))
						if gb.Laser.Misil.sprite.xscale < 0.9*gb.Sprite.xscale and gb.Laser.Scale == 0 then
							gb.Laser.Misil.sprite.xscale = gb.Laser.Misil.sprite.xscale + 0.1*gb.Sprite.xscale
						else
							gb.Laser.Scale = gb.Laser.Scale + 50
							gb.Laser.Misil.sprite.xscale = 0.9*gb.Sprite.xscale + 0.1*gb.Sprite.xscale*math.sin(math.rad(gb.Laser.Scale))
						end
						if Shield.rotation == gb.Sprite.rotation then
							if gb.Sprite.rotation == 90 then
								gb.Laser.Cuerpo.sprite.Scale(62*gb.Laser.Misil.sprite.xscale, math.abs(gb.X + (22 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)) - (320 - 67/2)))
							else
								gb.Laser.Cuerpo.sprite.Scale(62*gb.Laser.Misil.sprite.xscale, math.abs(gb.X + (22 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)) - (320 + 67/2)))
							end
							Shield.SetVar("Timer", 0)
						else
							if gb.Sprite.rotation == 90 then
								gb.Laser.Cuerpo.sprite.Scale(62*gb.Laser.Misil.sprite.xscale, math.abs(gb.X + (22 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)) - (320 + Arena.width/2)))
							else
								gb.Laser.Cuerpo.sprite.Scale(62*gb.Laser.Misil.sprite.xscale, math.abs(gb.X + (22 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)) - (320 - Arena.width/2)))
							end
						end
						gb.Laser.Cuerpo.MoveToAbs(gb.X + (22 + gb.Laser.Cuerpo.sprite.yscale/2 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (22 + gb.Laser.Cuerpo.sprite.yscale/2 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))
						gb.Laser.Rafaga.sprite.Scale(gb.Laser.Misil.sprite.xscale, gb.Laser.Misil.sprite.xscale)
						gb.Laser.Rafaga.MoveToAbs(gb.X + (22 - 23*gb.Laser.Misil.sprite.xscale + gb.Laser.Cuerpo.sprite.yscale + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (22 - 23*gb.Laser.Misil.sprite.xscale + gb.Laser.Cuerpo.sprite.yscale + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))
					end
					if not shake[1] then
						shake = {math.random(-4, 4), math.random(-4, 4)}
					end
				else
					gb.Laser.Misil.SetVar("No Damage", true)
					gb.Laser.Cuerpo.SetVar("No Damage", true)
					gb.Laser.Rafaga.SetVar("No Damage", true)
					if gb.Laser.Misil.sprite.xscale > 0 then
						gb.Laser.Misil.MoveToAbs(gb.X + (11 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (11 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))
						gb.Laser.Misil.sprite.xscale = gb.Laser.Misil.sprite.xscale - 0.05*gb.Sprite.xscale
						gb.Laser.Misil.sprite.alpha = gb.Laser.Misil.sprite.xscale
						if Shield.rotation == gb.Sprite.rotation then
							if gb.Sprite.rotation == 90 then
								gb.Laser.Cuerpo.sprite.Scale(62*gb.Laser.Misil.sprite.xscale, math.abs(gb.X + (22 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)) - (320 - 67/2)))
							else
								gb.Laser.Cuerpo.sprite.Scale(62*gb.Laser.Misil.sprite.xscale, math.abs(gb.X + (22 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)) - (320 + 67/2)))
							end
							Shield.SetVar("Timer", 0)
						else
							if gb.Sprite.rotation == 90 then
								gb.Laser.Cuerpo.sprite.Scale(62*gb.Laser.Misil.sprite.xscale, math.abs(gb.X + (22 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)) - (320 + Arena.width/2)))
							else
								gb.Laser.Cuerpo.sprite.Scale(62*gb.Laser.Misil.sprite.xscale, math.abs(gb.X + (22 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)) - (320 - Arena.width/2)))
							end
						end
						gb.Laser.Cuerpo.MoveToAbs(gb.X + (22 + gb.Laser.Cuerpo.sprite.yscale/2 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (22 + gb.Laser.Cuerpo.sprite.yscale/2 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))
						gb.Laser.Cuerpo.sprite.alpha = gb.Laser.Misil.sprite.xscale
						gb.Laser.Rafaga.sprite.Scale(gb.Laser.Misil.sprite.xscale, gb.Laser.Misil.sprite.xscale)
						gb.Laser.Rafaga.MoveToAbs(gb.X + (22 - 23*gb.Laser.Misil.sprite.xscale + gb.Laser.Cuerpo.sprite.yscale + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (22 - 23*gb.Laser.Misil.sprite.xscale + gb.Laser.Cuerpo.sprite.yscale + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))
						gb.Laser.Rafaga.sprite.alpha = gb.Laser.Misil.sprite.xscale
					else
						gb.Laser.Misil.Remove()
						gb.Laser.Cuerpo.Remove()
						gb.Laser.Rafaga.sprite.StopAnimation()
						gb.Laser.Rafaga.Remove()
						gb.Sprite.Remove()
						gb = nil
						table.remove(GB, i - tableaux)
						tableaux = tableaux + 1
					end
				end
			end
		end
		if gb and shake then
			gb.Sprite.MoveTo(gb.X + (shake[1] or 0), gb.Y + (shake[2] or 0))
			if gb.Laser then
				gb.Laser.Misil.Move((shake[1] or 0), (shake[2] or 0))
				gb.Laser.Cuerpo.Move((shake[1] or 0), (shake[2] or 0))
				gb.Laser.Rafaga.Move((shake[1] or 0), (shake[2] or 0))
			end
		end
	end
	tableaux = 0
	for i=1,#GB2 do
		local gb = GB2[i - tableaux]
		if not gb.X then
			gb.X = gb.Sprite.x
		end
		if not gb.Y then
			gb.Y = gb.Sprite.y
		end
		if gb.Type == "Papyrus" then
			gb.distance = 26
		elseif gb.Type == "Sans" then
			gb.distance = 38
		end
		gb.Sprite.xscale = (gb.Scale or 1)
		if gb.Animacion then
			if not gb.Animacion.timer then
				gb.Animacion.timer = 0
			end
			gb.Animacion.timer = gb.Animacion.timer + 1
			gb.X = gb.Animacion.DatosIniciales.X + (gb.Animacion.DatosFinales.X - gb.Animacion.DatosIniciales.X)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30))))
			gb.Y = gb.Animacion.DatosIniciales.Y + (gb.Animacion.DatosFinales.Y - gb.Animacion.DatosIniciales.Y)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30))))
			gb.Sprite.MoveTo(gb.X, gb.Y)
			while gb.Animacion.DatosIniciales.rotation >= 360 or gb.Animacion.DatosIniciales.rotation < 0 do
				if gb.Animacion.DatosIniciales.rotation < 0 then
					gb.Animacion.DatosIniciales.rotation = gb.Animacion.DatosIniciales.rotation + 360
				else
					gb.Animacion.DatosIniciales.rotation = gb.Animacion.DatosIniciales.rotation - 360
				end
			end
			while gb.Animacion.DatosFinales.rotation >= 360 or gb.Animacion.DatosFinales.rotation < 0 do
				if gb.Animacion.DatosFinales.rotation < 0 then
					gb.Animacion.DatosFinales.rotation = gb.Animacion.DatosFinales.rotation + 360
				else
					gb.Animacion.DatosFinales.rotation = gb.Animacion.DatosFinales.rotation - 360
				end
			end
			if gb.Animacion.DatosFinales.rotation - gb.Animacion.DatosIniciales.rotation <= 180 and gb.Animacion.DatosFinales.rotation - gb.Animacion.DatosIniciales.rotation >= -180 then
				gb.Sprite.rotation = gb.Animacion.DatosIniciales.rotation - (gb.Animacion.DatosIniciales.rotation - gb.Animacion.DatosFinales.rotation)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30))))
			else
				gb.Sprite.rotation = gb.Animacion.DatosIniciales.rotation - (360 - (gb.Animacion.DatosFinales.rotation - 180 + gb.Animacion.DatosIniciales.rotation - 180)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30)))))
			end
			if gb.Animacion.timer >= (gb.Animacion.VelAppearing or 30) then
				gb.Animacion = nil
				gb.Done = true
			end
		else
			if gb.Rotation and not gb.Done then
				gb.Sprite.rotation = gb.Rotation
			end
			gb.Delay = gb.Delay - 1
		end
		if gb.Vel then
			gb.X = gb.X - gb.Vel*math.sin(math.rad(gb.Sprite.rotation))
			gb.Y = gb.Y + gb.Vel*math.cos(math.rad(gb.Sprite.rotation))
			gb.Vel = gb.Vel*1.1
			if gb.X < -100 or gb.X > 740 or gb.Y < -100 or gb.Y > 580 then
				gb.Vel = 0
			end
		end
		gb.Sprite.MoveTo(gb.X, gb.Y)
		if (gb.Delay < 0 and gb.Type == "Papyrus") or (gb.Delay < 6 and gb.Type == "Sans") then
			if gb.Delay == 5 then
				gb.Sprite.Set("Bullets/GB Sans/1")
			elseif gb.Delay == 3 then
				gb.Sprite.Set("Bullets/GB Sans/2")
			elseif gb.Delay == 1 then
				gb.Sprite.Set("Bullets/GB Sans/3")
			elseif gb.Delay == -1 then
				if gb.Type == "Papyrus" then
					gb.Sprite.Set("Bullets/GB Papyrus/1")
				else
					gb.Sprite.SetAnimation({"Bullets/GB Sans/4","Bullets/GB Sans/5"}, 0.04)
				end
				gb.Vel = 2
				Audio.PlaySound("gasterfire")
			elseif gb.Delay <= -2 then
				if gb.Duration > 0 then
					gb.Duration = gb.Duration - 1
					if not gb.Laser then
						gb.Laser = {Misil = CreateProjectileAbs("Bullets/GB Laser", gb.X + (640 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (640 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))}
						gb.Laser.Misil.sprite.xscale = 0
						gb.Laser.Misil.sprite.rotation = gb.Sprite.rotation
						gb.Laser.Scale = 0
					else
						gb.Laser.Misil.MoveToAbs(gb.X + (640 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (640 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))
						if gb.LessFat then
							if gb.Laser.Misil.sprite.xscale < 0.6*gb.Sprite.xscale and gb.Laser.Scale == 0 then
								gb.Laser.Misil.sprite.xscale = gb.Laser.Misil.sprite.xscale + 0.1*gb.Sprite.xscale
							else
								gb.Laser.Scale = gb.Laser.Scale + 50
								gb.Laser.Misil.sprite.xscale = 0.6*gb.Sprite.xscale + 0.1*gb.Sprite.xscale*math.sin(math.rad(gb.Laser.Scale))
							end
						else
							if gb.Laser.Misil.sprite.xscale < 0.9*gb.Sprite.xscale and gb.Laser.Scale == 0 then
								gb.Laser.Misil.sprite.xscale = gb.Laser.Misil.sprite.xscale + 0.1*gb.Sprite.xscale
							else
								gb.Laser.Scale = gb.Laser.Scale + 50
								gb.Laser.Misil.sprite.xscale = 0.9*gb.Sprite.xscale + 0.1*gb.Sprite.xscale*math.sin(math.rad(gb.Laser.Scale))
							end
						end
					end
					if not gb.NoShake and #shake <= 0 then
						shake = {math.random(-4, 4), math.random(-4, 4)}
					end
				else
					gb.Laser.Misil.SetVar("No Damage", true)
					if gb.Laser.Misil.sprite.xscale > 0 then
						gb.Laser.Misil.MoveToAbs(gb.X + (640 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (640 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))
						gb.Laser.Misil.sprite.xscale = gb.Laser.Misil.sprite.xscale - 0.05*gb.Sprite.xscale
						gb.Laser.Misil.sprite.alpha = gb.Laser.Misil.sprite.xscale
					else
						gb.Laser.Misil.Remove()
						gb.Sprite.Remove()
						gb = nil
						table.remove(GB2, i - tableaux)
						tableaux = tableaux + 1
					end
				end
			end
		end
		if gb and shake then
			gb.Sprite.MoveTo(gb.X + (shake[1] or 0), gb.Y + (shake[2] or 0))
			if gb.Laser then
				gb.Laser.Misil.Move((shake[1] or 0), (shake[2] or 0))
			end
		end
	end
	tableaux = 0
	Arena.MoveTo(320 + (shake[1] or 0), AuxY + (shake[2] or 0), false, true)
	if Encounter["phase"] <= 3 then
		Encounter.Call("PapsMoveTo", {Paps.X + (shake[1] or 0), Paps.Y + (shake[2] or 0)})
	end
	if Encounter["Sans"]["Legs"] then
		Encounter["Sans"]["Legs"].MoveTo(Sans.X + (shake[1] or 0), Sans.Y + (shake[2] or 0))
	end
	if Encounter["Undyne"]["Legs"] then
		Encounter["Undyne"]["Legs"].MoveTo(Undyne.X + (shake[1] or 0), Undyne.Y + (shake[2] or 0))
	end
	Encounter.Call("StatusMoveTo", {320 + (shake[1] or 0), 70.5 + (shake[2] or 0)})
	Encounter.Call("ButtonMoveTo", {"Fight", 87 + (shake[1] or 0), 27 + (shake[2] or 0)})
	Encounter.Call("ButtonMoveTo", {"Act", 240 + (shake[1] or 0), 27 + (shake[2] or 0)})
	Encounter.Call("ButtonMoveTo", {"Item", 400 + (shake[1] or 0), 27 + (shake[2] or 0)})
	Encounter.Call("ButtonMoveTo", {"Mercy", 555 + (shake[1] or 0), 27 + (shake[2] or 0)})
	for i=1,#Spears do
		local Datos = Spears[i - tableaux]
		if not Datos.Backwards then
			Datos.Distance = Datos.Distance - Datos.Speed
			Datos.Bullet.MoveToAbs(320 - Datos.Distance*math.sin(math.rad(Datos.Direction)), 240 + Datos.Distance*math.cos(math.rad(Datos.Direction)))
		else
			if not Datos.Suma then
				Datos.Suma = 180
			end
			if Datos.Distance > 70 then
				Datos.Distance = math.max(Datos.Distance - Datos.Speed, 70)
				Datos.Bullet.MoveToAbs(320 - Datos.Distance*math.sin(math.rad(Datos.Direction + 180)), 240 + Datos.Distance*math.cos(math.rad(Datos.Direction + 180)))
			elseif Datos.Distance == 70 and Datos.Suma < 360 then
				Datos.Suma = math.min(Datos.Suma + (Datos.VelRot or 15), 360)
				Datos.Bullet.MoveToAbs(320 - Datos.Distance*math.sin(math.rad(Datos.Direction + Datos.Suma)), 240 + Datos.Distance*math.cos(math.rad(Datos.Direction + Datos.Suma)))
			else
				Datos.Distance = Datos.Distance - Datos.Speed
				Datos.Bullet.MoveToAbs(320 - Datos.Distance*math.sin(math.rad(Datos.Direction)), 240 + Datos.Distance*math.cos(math.rad(Datos.Direction)))
			end
		end
		Datos.Bullet.sprite.rotation = Datos.Direction
		if Shield and Datos.Distance <= 50 and Datos.Direction == Shield.rotation then
			Audio.PlaySound("ding")
			Shield.SetVar("Timer", 0)
			Datos.Bullet.Remove()
			table.remove(Spears, i - tableaux)
			tableaux = tableaux + 1
		elseif Datos.Distance <= 5 then
			Datos.Bullet.Remove()
			table.remove(Spears, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	local color = 1000000
	for i=1,#Spears do
		if not Spears[i].Backwards and Spears[i].Turn < color then
			color = Spears[i].Turn
		end
	end
	for i=1,#Spears do
		if not Spears[i].Backwards and Spears[i].Turn == color then
			Spears[i].Bullet.sprite.Set("Bullets/Arrow Red")
		end
	end
	for i=1,#Bones1 do
		local Datos = Bones1[i - tableaux]
		if not Datos.Blue then
			Datos.Distance = Datos.Distance - Datos.Speed
			Datos.Bullet.MoveToAbs(320 - Datos.Distance*math.sin(math.rad(Datos.Direction)), 240 + Datos.Distance*math.cos(math.rad(Datos.Direction)))
			Datos.Bullet.sprite.rotation = Datos.Direction
			if Shield and Datos.Distance <= 56 and Datos.Direction == Shield.rotation then
				Audio.PlaySound("ding")
				Shield.SetVar("Timer", 0)
				Datos.Bullet.Remove()
				table.remove(Bones1, i - tableaux)
				tableaux = tableaux + 1
			elseif Datos.Distance <= 5 then
				Datos.Bullet.Remove()
				table.remove(Bones1, i - tableaux)
				tableaux = tableaux + 1
			end
		else
			Datos.Distance = Datos.Distance - Datos.Speed
			Datos.Bullet.SetVar("No Damage", true)
			Datos.Bullet.sprite.color = {33/255, 197/255, 1}
			Datos.Bullet.MoveToAbs(320 - Datos.Distance*math.sin(math.rad(Datos.Direction)), 240 + Datos.Distance*math.cos(math.rad(Datos.Direction)))
			Datos.Bullet.sprite.rotation = Datos.Direction
			if Shield and ((Datos.Distance >= 0 and Datos.Distance <= 56 and Datos.Direction == Shield.rotation) or (Datos.Distance >= -56 and Datos.Distance <= 0 and (Datos.Direction + 180)%360 == Shield.rotation)) then
				Audio.PlaySound("ding")
				Shield.SetVar("Timer", 0)
				if not Player.isHurting then
					if Player.hp > 20 then
						Player.Hurt(20)
					else
						finish = true
					end
				end
				Datos.Bullet.Remove()
				table.remove(Bones1, i - tableaux)
				tableaux = tableaux + 1
			elseif Datos.Distance <= -360 then
				Datos.Bullet.Remove()
				table.remove(Bones1, i - tableaux)
				tableaux = tableaux + 1
			end
		end
	end
	tableaux = 0
	for i=1,#Bones2 do
		local Datos = Bones2[i - tableaux]
		if not Datos.X then
			Datos.X = Datos.Body.absx
		end
		if not Datos.Y then
			Datos.Y = Datos.Body.absy
		end
		Datos.X = Datos.X + Datos.Vel
		Datos.Body.sprite.yscale = Datos.Scale
		Datos.Legs.sprite.rotation = 180
		Datos.Body.MoveToAbs(Datos.X, Datos.Y)
		Datos.Head.MoveToAbs(Datos.X, Datos.Y + Datos.Scale/2 + 3)
		Datos.Legs.MoveToAbs(Datos.X, Datos.Y - Datos.Scale/2 - 3)
		if Datos.X <= Arena.x - Arena.width/2 - 2 or Datos.X >= Arena.x + Arena.width/2 + 2 then
			Datos.Body.Remove()
			Datos.Head.Remove()
			Datos.Legs.Remove()
			table.remove(Bones2, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	for i=1,#Sprites do
		if Sprites[i - tableaux].isactive then
			Sprites[i - tableaux].MoveTo(Sprites[i - tableaux].GetVar("Pos")[1] + (shake[1] or 0), Sprites[i - tableaux].GetVar("Pos")[2] + (shake[2] or 0))
		else
			table.remove(Sprites, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	for i=1,#HuesosSuelo do
		local bullet = HuesosSuelo[i - tableaux]
		if not bullet.X then
			bullet.X = bullet.Misil.absx
		end
		if not bullet.Y then
			bullet.Y = bullet.Misil.absy
		end
		if not bullet.Scale.Direction then
			bullet.Scale.Direction = "Up"
		end
		if not bullet.Scale.Current then
			bullet.Scale.Current = 0
		end
		if not bullet.Rotacion then
			bullet.Rotacion = 0
		end
		if bullet.Scale.Current < bullet.Scale.MaxHeight and bullet.Scale.Direction == "Up" then
			bullet.Scale.Current = math.min(bullet.Scale.Current + bullet.Scale.Vel, bullet.Scale.MaxHeight)
			if bullet.Scale.Current >= bullet.Scale.MaxHeight then
				bullet.Scale.Direction = "Waiting"
			end
		elseif bullet.Scale.Direction == "Waiting" then
			if not bullet.Timer then
				bullet.Timer = 0
			end
			bullet.Timer = bullet.Timer + 1
			if bullet.Timer >= (bullet.Duration or 30) then
				bullet.Scale.Direction = "Down"
			end
		elseif bullet.Scale.Current > 0 and bullet.Scale.Direction == "Down" then
			bullet.Scale.Current = math.max(bullet.Scale.Current - bullet.Scale.Vel, 0)
		end
		bullet.Misil.sprite.yscale = bullet.Scale.Current
		bullet.Misil.sprite.rotation = bullet.Rotacion
		bullet.Misil.MoveToAbs(bullet.X + (shake[1] or 0) - bullet.Scale.Current/2*math.sin(math.rad(bullet.Rotacion)), bullet.Y + (shake[2] or 0) + bullet.Scale.Current/2*math.cos(math.rad(bullet.Rotacion)))
		if bullet.Head then
			bullet.Head.MoveToAbs(bullet.X + (shake[1] or 0) - (bullet.Scale.Current + 3)*math.sin(math.rad(bullet.Rotacion)), bullet.Y + (shake[2] or 0) + (bullet.Scale.Current + 3)*math.cos(math.rad(bullet.Rotacion)))
			bullet.Head.sprite.rotation = bullet.Rotacion
		end
		if bullet.Legs then
			bullet.Legs.MoveToAbs(bullet.X + (shake[1] or 0) + (bullet.Scale.Current + 3)*math.sin(math.rad(bullet.Rotacion)), bullet.Y + (shake[2] or 0) - (bullet.Scale.Current + 3)*math.cos(math.rad(bullet.Rotacion)))
			bullet.Legs.sprite.rotation = bullet.Rotacion + 180
		end
		if bullet.Scale.Current <= 0 and bullet.Scale.Direction == "Down" then
			bullet.Misil.Remove()
			if bullet.Head then
				bullet.Head.Remove()
			end
			if bullet.Legs then
				bullet.Legs.Remove()
			end
			bullet = nil
			table.remove(HuesosSuelo, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	if Shield and Shield.GetVar("Timer") then
		Shield.SetVar("Timer", Shield.GetVar("Timer") + 1)
		if Shield.GetVar("Timer") == 1 then
			Shield.Set("Specials/Shield 2")
		elseif Shield.GetVar("Timer") == 10 then
			Shield.Set("Specials/Shield 1")
			Shield.SetVar("Timer", nil)
		end
	end
	if state == 0 then --Don't move
		Player.MoveToAbs(newpX + (shake[1] or 0), newpY + (shake[2] or 0), true)
	elseif state == 1 then -- Down
		if Input.Right > 0 then
			newpX = newpX + 3
		end
		if Input.Left > 0 then
			newpX = newpX - 3
		end
		if newpY < 105 then
			if Input.Up > 0 then
				jump = maxjump
			else
				newpY = 103
				jump = 0
			end
		elseif jump < 3 and jump > -3 then
			jump = jump - 0.5
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 1.5
		else
			jump = (jump/1.001) - 1
		end
		if Input.Up < 0 and jump > 3 then
			jump = 2
		end
		newpY = math.max(newpY + (jump/10), 103)
		if newpX < 328 - Arena.width/2 then
			newpX = 328 - Arena.width/2
		elseif newpX > 312 + Arena.width/2 then
			newpX = 312 + Arena.width/2
		end
		Player.MoveToAbs(newpX + (shake[1] or 0), newpY + (shake[2] or 0), true)
    elseif state == 2 then -- Left
		if Input.Up > 0 then
			newpY = newpY + 3
		end
		if Input.Down > 0 then
			newpY = newpY - 3
		end
		if newpX < 330 - Arena.width/2 then
			if jump < -100 and phases[1] <= 18 then
				slamtimer = 10
			end
			if Input.Right > 0 then
				jump = maxjump
			else
				newpX = 328 - Arena.width/2
				jump = 0
			end
		elseif jump < 3 and jump > -3 then
			jump = jump - 0.5
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 1.5
		else
			jump = (jump/1.001) - 1
		end
		if Input.Right < 0 and jump > 3 then
			jump = 2
		end
		newpX = math.max(newpX + (jump/10), 328 - Arena.width/2)
		if newpY < 103 then
			newpY = 103
		elseif newpY > 87 + Arena.height then
			newpY = 87 + Arena.height
		end
		Player.MoveToAbs(newpX + (shake[1] or 0), newpY + (shake[2] or 0), true)
	elseif state == 3 then -- Up
		if Input.Right > 0 then
			newpX = newpX + 3
		end
		if Input.Left > 0 then
			newpX = newpX - 3
		end
		if newpY > 85 + Arena.height then
			if Input.Down > 0 then
				jump = maxjump
			else
				newpY = 87 + Arena.height
				jump = 0
			end
			mantener = nil
		elseif jump < 3 and jump > -3 then
			jump = jump - 0.5
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 1.5
		else
			jump = (jump/1.001) - 1
		end
		if Input.Down < 0 and jump > 3 then
			jump = 2
		end
		newpY = math.min(newpY - (jump/10), 87 + Arena.height)
		if newpX < 328 - Arena.width/2 then
			newpX = 328 - Arena.width/2
		elseif newpX > 312 + Arena.width/2 then
			newpX = 312 + Arena.width/2
		end
		Player.MoveToAbs(newpX + (shake[1] or 0), newpY + (shake[2] or 0), true)
    elseif state == 4 then -- Right
		if Input.Up > 0 then
			newpY = newpY + 3
		end
		if Input.Down > 0 then
			newpY = newpY - 3
		end
		if newpX > 310 + Arena.width/2 then
			if jump < -100 and phases[1] <= 18 then
				slamtimer = 10
			end
			if Input.Left > 0 then
				jump = maxjump
			else
				newpX = 312 + Arena.width/2
				jump = 0
			end
		elseif jump < 3 and jump > -3 then
			jump = jump - 0.5
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 1.5
		else
			jump = (jump/1.001) - 1
		end
		if Input.Left < 0 and jump > 3 then
			jump = 2
		end
		newpX = math.min(newpX - (jump/10), 312 + Arena.width/2)
		if newpY < 103 then
			newpY = 103
		elseif newpY > 87 + Arena.height then
			newpY = 87 + Arena.height
		end
		Player.MoveToAbs(newpX + (shake[1] or 0), newpY + (shake[2] or 0), true)
    end
	if Green then
		Green.MoveTo(newpX + (shake[1] or 0), newpY + (shake[2] or 0))
	end
	if Shield then
		Shield.MoveTo(newpX + (shake[1] or 0), newpY + (shake[2] or 0))
	end
	if Black then
		Black.layer = "Bottom"
		Black.layer = "BelowArena"
	end
	if finish then
		EndEverything()
	end
end

function OnHit(bullet)
	if not bullet.GetVar("No Damage") and not Player.isHurting then
		if Encounter["PHP"] then
			Player.Hurt(math.min(Player.hp - 1, 40)) --This doesn't count, it's just on purpose
		else
			if Player.hp > 20 then
				Player.Hurt(20)
			else
				EndEverything()
			end
			Encounter["NOHIT"] = nil
		end
	end
end

function EndEverything()
	if Green then
		Green.Remove()
	end
	if Shield then
		Shield.Remove()
	end
	for i=1,#GB do
		GB[i - tableaux].Sprite.Remove()
		if GB[i - tableaux].Laser then
			GB[i - tableaux].Laser.Misil.Remove()
			GB[i - tableaux].Laser.Cuerpo.Remove()
			GB[i - tableaux].Laser.Rafaga.Remove()
		end
		table.remove(GB, i - tableaux)
		tableaux = tableaux + 1
	end
	tableaux = 0
	for i=1,#GB2 do
		GB2[i - tableaux].Sprite.Remove()
		if GB2[i - tableaux].Laser then
			GB2[i - tableaux].Laser.Misil.Remove()
		end
		table.remove(GB2, i - tableaux)
		tableaux = tableaux + 1
	end
	tableaux = 0
	for i=1,#Sprites do
		Sprites[i - tableaux].Remove()
		table.remove(Sprites, i - tableaux)
		tableaux = tableaux + 1
	end
	tableaux = 0
	if Skip then
		Skip.Remove()
	end
	if Black then
		Black.Remove()
	end
	if Black2 then
		Black2.Remove()
	end
	Bubble("", "", "", "", "", "", 1)
	Encounter["X"] = Player.absx
	Encounter["Y"] = Player.absy
	Encounter["nextwaves"] = {"Game Over"}
	State("ACTIONSELECT")
	State("DEFENDING")
end